package com.yougou.data.model;

import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.List;

public class GoodsDetail {
    @SerializedName("goods_id")
    private int goodsId;
    
    @SerializedName("goods_name")
    private String goodsName;
    
    @SerializedName("goods_price")
    private double goodsPrice;
    
    @SerializedName("market_price")
    private double marketPrice;
    
    @SerializedName("goods_introduce")
    private String goodsIntroduce;
    
    @SerializedName("pics")
    private List<GoodsPic> pics;
    
    @SerializedName("goods_number")
    private int stock;
    
    private int sales;
    
    public int getGoodsId() {
        return goodsId;
    }
    
    public void setGoodsId(int goodsId) {
        this.goodsId = goodsId;
    }
    
    public String getGoodsName() {
        return goodsName;
    }
    
    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }
    
    public double getGoodsPrice() {
        return goodsPrice;
    }
    
    public void setGoodsPrice(double goodsPrice) {
        this.goodsPrice = goodsPrice;
    }
    
    public double getMarketPrice() {
        return marketPrice;
    }
    
    public void setMarketPrice(double marketPrice) {
        this.marketPrice = marketPrice;
    }
    
    public String getGoodsIntroduce() {
        return goodsIntroduce;
    }
    
    public void setGoodsIntroduce(String goodsIntroduce) {
        this.goodsIntroduce = goodsIntroduce;
    }
    
    public List<GoodsPic> getPics() {
        return pics;
    }
    
    public void setPics(List<GoodsPic> pics) {
        this.pics = pics;
    }
    
    
    public List<String> getPicUrls() {
        List<String> urls = new ArrayList<>();
        if (pics != null) {
            for (GoodsPic pic : pics) {
                urls.add(pic.getPicsBigUrl());
            }
        }
        return urls;
    }
    
    public int getStock() {
        return stock;
    }
    
    public void setStock(int stock) {
        this.stock = stock;
    }
    
    public int getSales() {
        return sales;
    }
    
    public void setSales(int sales) {
        this.sales = sales;
    }
    
    
    public Goods toGoods() {
        Goods goods = new Goods();
        goods.setGoodsId(goodsId);
        goods.setGoodsName(goodsName);
        goods.setGoodsPrice(goodsPrice);
        
        // 设置图片 - 保存到多个字段以确保在各种场景下都能显示
        if (pics != null && !pics.isEmpty()) {
            GoodsPic pic = pics.get(0);
            String imageUrl = pic.getPicsBigUrl(); // 优先使用大图
            if (imageUrl == null || imageUrl.isEmpty()) {
                imageUrl = pic.getPicsMidUrl(); // 其次中图
            }
            if (imageUrl == null || imageUrl.isEmpty()) {
                imageUrl = pic.getPicsSmaUrl(); // 最后小图
            }
            
            // 保存到所有图片字段，确保兼容性
            if (imageUrl != null && !imageUrl.isEmpty()) {
                goods.setGoodsPic(imageUrl);
                goods.setGoodsSmallLogo(imageUrl);
                goods.setGoodsBigLogo(imageUrl);
            }
        }
        
        return goods;
    }
    
    
    public static class GoodsPic {
        @SerializedName("pics_id")
        private int picsId;
        
        @SerializedName("goods_id")
        private int goodsId;
        
        @SerializedName("pics_big")
        private String picsBig;
        
        @SerializedName("pics_mid")
        private String picsMid;
        
        @SerializedName("pics_sma")
        private String picsSma;
        
        @SerializedName("pics_big_url")
        private String picsBigUrl;
        
        @SerializedName("pics_mid_url")
        private String picsMidUrl;
        
        @SerializedName("pics_sma_url")
        private String picsSmaUrl;
        
        public int getPicsId() {
            return picsId;
        }
        
        public void setPicsId(int picsId) {
            this.picsId = picsId;
        }
        
        public int getGoodsId() {
            return goodsId;
        }
        
        public void setGoodsId(int goodsId) {
            this.goodsId = goodsId;
        }
        
        public String getPicsBig() {
            return picsBig;
        }
        
        public void setPicsBig(String picsBig) {
            this.picsBig = picsBig;
        }
        
        public String getPicsMid() {
            return picsMid;
        }
        
        public void setPicsMid(String picsMid) {
            this.picsMid = picsMid;
        }
        
        public String getPicsSma() {
            return picsSma;
        }
        
        public void setPicsSma(String picsSma) {
            this.picsSma = picsSma;
        }
        
        public String getPicsBigUrl() {
            return picsBigUrl;
        }
        
        public void setPicsBigUrl(String picsBigUrl) {
            this.picsBigUrl = picsBigUrl;
        }
        
        public String getPicsMidUrl() {
            return picsMidUrl;
        }
        
        public void setPicsMidUrl(String picsMidUrl) {
            this.picsMidUrl = picsMidUrl;
        }
        
        public String getPicsSmaUrl() {
            return picsSmaUrl;
        }
        
        public void setPicsSmaUrl(String picsSmaUrl) {
            this.picsSmaUrl = picsSmaUrl;
        }
    }
}

